package com.navigationtest;

import android.view.View;

import com.hjq.bar.OnTitleBarListener;
import com.myatest.BR;
import com.myatest.R;
import com.pbase.tools.Logger;
import com.pbase.ui.page.DataBindingConfig;

import androidx.navigation.NavController;
import androidx.navigation.Navigation;

/**
 * User: psn
 * Date: 2021/12/11
 */
public class Test1Fragment extends NavigationViewFragment {
    private Test1ViewModel mViewModel;

    @Override
    protected void onCreateViewBefore() {

    }

    @Override
    protected void onCreateViewAfter() {
         super.onCreateViewAfter();
    }

    @Override
    protected void initViewModel() {
        mViewModel = getFragmentScopeViewModel(Test1ViewModel.class);
    }

    @Override
    protected DataBindingConfig getDataBindingConfig() {
        return new DataBindingConfig(R.layout.frg_text1, BR.vm, mViewModel)
                .addBindingParam(BR.OnTitleBarListener, new TitleBarListener())
                .addBindingParam(BR.click, new Onclick()) ;
    }

    public class Onclick {
        public void btn_a(View v) {
            Logger.e(getClass(),"btn_a");
//            NavController controller = Navigation.findNavController( v);//找到button归属的controller
//            controller.navigate(R.id.action_test5Fragment_to_include1);
//            ((RouterActivity) Test1Fragment.this.requireActivity()).navigation(R.id.action_startFragment_to_include1);
            NavController controller = Navigation.findNavController( v);//找到button归属的controller
            controller.navigate(R.id.action_startFragment_to_include1);
        }

    }


    public class TitleBarListener implements OnTitleBarListener {

        @Override
        public void onLeftClick(View view) {
            Logger.e(getClass(),"onLeftClick");
//            getChildFragmentManager().popBackStack();
            left();
        }

        @Override
        public void onTitleClick(View view) {

        }

        @Override
        public void onRightClick(View view) {

        }
    }


}
